﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.TaskScheduling.Migrations
{
    /// <inheritdoc />
    public partial class add_table_EventMsgRec : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            //migrationBuilder.AddColumn<int>(
            //    name: "ManualFlag",
            //    schema: "TaskScheduling",
            //    table: "TS_SampleTestTasks",
            //    type: "int",
            //    nullable: false,
            //    defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "TS_EventMsgRec",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TopicFullPath = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MsgTopicName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    MsgCont = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    EventMsgOperStas = table.Column<int>(type: "int", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_EventMsgRec", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TS_EventMsgTopic",
                schema: "TaskScheduling",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    EventMsgTopicCodg = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    EventMsgTopicName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    TopicFullPath = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Srtno = table.Column<int>(type: "int", nullable: false),
                    LvIndex = table.Column<int>(type: "int", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "bit", nullable: false),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TS_EventMsgTopic", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TS_EventMsgTopic_TS_EventMsgTopic_ParentId",
                        column: x => x.ParentId,
                        principalSchema: "TaskScheduling",
                        principalTable: "TS_EventMsgTopic",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_TS_EventMsgTopic_ParentId",
                schema: "TaskScheduling",
                table: "TS_EventMsgTopic",
                column: "ParentId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TS_EventMsgRec",
                schema: "TaskScheduling");

            migrationBuilder.DropTable(
                name: "TS_EventMsgTopic",
                schema: "TaskScheduling");

            migrationBuilder.DropColumn(
                name: "ManualFlag",
                schema: "TaskScheduling",
                table: "TS_SampleTestTasks");
        }
    }
}
